package com.company.base.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.company.base.common.WeChatConstant;
import com.company.site.mode.menu.Button;
import com.company.site.mode.menu.CommonButton;
import com.company.site.mode.menu.ComplexButton;
import com.company.site.mode.menu.Menu;
import com.company.site.mode.menu.ViewButton;
import com.company.site.mode.token.AccessToken;

public class MenuManager {
	private static Logger log = LoggerFactory.getLogger(MenuManager.class);

	public static void main(String[] args) {
					
		// 调用接口获取access_token
//		AccessToken at = TokenThread.accessToken;
		AccessToken at = WeChatUtil.getAccessToken(WeChatConstant.appId, WeChatConstant.appSecret);	
		System.out.println("accessToken" + at.getToken());

		if (null != at) {
			// 调用接口创建菜单
			int result = WeChatUtil.createMenu(getMenu(), at.getToken());
			System.out.println(result);
			// 判断菜单创建结果
			if (0 == result)
				log.info("菜单创建成功");
			else
				log.info("菜单创建失败，错误码" + result);
		}
		
		
//		if (null != at) {
//			// 调用接口删除菜单
//			int result = WeChatUtil.deleteMenu(at.getToken());
//			System.out.println(result);
//			// 判断菜单删除结果
//			if (0 == result)
//				log.info("菜单删除成功");
//			else
//				log.info("菜单删除失败，错误码" + result);
//		}
		
	}

	public void deleteMenu(){
	
	}
	
	
	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	private static Menu getMenu() {
//		ViewButton btn1 = new ViewButton();
//		btn1.setName("企业简介");
//		btn1.setType("view");
//		btn1.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210303586&idx=1&sn=11e96ce20bf37437826eed4f75391977&scene=18#wechat_redirect");
//		ViewButton btn2 = new ViewButton();
//		btn2.setName("品牌档案");
//		btn2.setType("view");
//		btn2.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210303586&idx=2&sn=7aa360b7937cea92fd6ab3c3af25c529&scene=18#wechat_redirect");
//		ViewButton btn3 = new ViewButton();
//		btn3.setName("终端形象");
//		btn3.setType("view");
//		btn3.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210303586&idx=4&sn=267ec210b2bd09e901930f8eef74a421&scene=18#wechat_redirect");
//		ComplexButton mainBtn1 = new ComplexButton();
//		mainBtn1.setName("企业简介");
//		mainBtn1.setSub_button(new Button[] { btn1,btn2,btn3});
//		
//		ViewButton btn4 = new ViewButton();
//		btn4.setName("男装系列");
//		btn4.setType("view");
//		btn4.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=204675089&idx=2&sn=69ec76d12b0eca02604774935a6c9aeb&scene=18#wechat_redirect");
//		ViewButton btn5 = new ViewButton();
//		btn5.setName("羽绒服系列");
//		btn5.setType("view");
//		btn5.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210303586&idx=3&sn=d73b7117a862abdf28548feed2c36c00&scene=18#wechat_redirect");
//		ViewButton btn6 = new ViewButton();
//		btn6.setName("广告投票");
//		btn6.setType("view");
//		btn6.setUrl("http://www.wbedc.com/wenjuan/vote.htm");
//		ComplexButton mainBtn2 = new ComplexButton();
//		mainBtn2.setName("广告征集");
//		mainBtn2.setSub_button(new Button[] { btn4,btn5,btn6});
//		
//		ViewButton btn7 = new ViewButton();
//		btn7.setName("地址");
//		btn7.setType("view");
//		btn7.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210032386&idx=1&sn=60a21c4f5715ff29c8c76ca3fcc764da&scene=18#wechat_redirect");
//		ViewButton btn8 = new ViewButton();
//		btn8.setName("加盟优势/条件");
//		btn8.setType("view");
//		btn8.setUrl("http://mp.weixin.qq.com/s?__biz=MzA5Mjk4MDgwMQ==&mid=210303586&idx=5&sn=9365165ee5250de2d61160632949cab3&scene=18#wechat_redirect");
//		ComplexButton mainBtn3 = new ComplexButton();
//		mainBtn3.setName("联系我们");
//		mainBtn3.setSub_button(new Button[] { btn7,btn8});
		
		ViewButton btn1 = new ViewButton();
		btn1.setName("红木知识等级考试");
		btn1.setType("view");
		btn1.setUrl("http://www.wbedc.com/wenjuan/main.htm");
		
		Menu menu = new Menu();
		menu.setButton(new Button[] {btn1});
		return menu;
	}
}
